﻿using System;
using System.Drawing;

namespace dk.Helper.Base.Core
{
    public class Village : IVillage
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="Village"/> class.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="name">The name.</param>
        /// <param name="coord">The coord.</param>
        /// <param name="playerId">The player id.</param>
        /// <param name="points">The points.</param>
        /// <param name="rank">The rank.</param>
        public Village(int id, string name, Point coord, int playerId, int points, int rank)
        {
            ID = id;
            Name = name;
            Coord = coord;
            PlayerID = playerId;
            Points = points;
            Rank = rank;
        }

        #region IVillage Members

        /// <summary>
        /// Gets the ID.
        /// </summary>
        public int ID { get; private set; }

        /// <summary>
        /// Gets the name.
        /// </summary>
        public string Name { get; private set; }

        /// <summary>
        /// Gets the coord.
        /// </summary>
        public Point Coord { get; private set; }

        /// <summary>
        /// Gets the player ID.
        /// </summary>
        public int PlayerID { get; private set; }

        /// <summary>
        /// Gets the points.
        /// </summary>
        public int Points { get; private set; }

        /// <summary>
        /// Gets the rank.
        /// </summary>
        public int Rank { get; private set; }

        /// <summary>
        /// Gets the distance to.
        /// </summary>
        /// <param name="village">The village.</param>
        /// <returns></returns>
        public double GetDistanceTo(IVillage village)
        {
            double x = Math.Abs(Coord.X - village.Coord.X);
            double y = Math.Abs(Coord.Y - village.Coord.Y);

            return Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2));
        }

        /// <summary>
        /// Formats the value of the current instance using the specified format.
        /// </summary>
        /// <returns>
        /// The value of the current instance in the specified format.
        /// </returns>
        /// <param name="format">The format to use.-or- A null reference (Nothing in Visual Basic) to use the default format defined for the type of the <see cref="T:System.IFormattable"/> implementation. </param><param name="formatProvider">The provider to use to format the value.-or- A null reference (Nothing in Visual Basic) to obtain the numeric format information from the current locale setting of the operating system. </param><filterpriority>2</filterpriority>
        public string ToString(string format, IFormatProvider formatProvider)
        {
            return ToString();
        }

        #endregion

        public override string ToString()
        {
            return Name + " (" + Coord.X + "|" + Coord.Y + ")";
        }
    }
}